{template 'system/common/header'}
<div class="dm-subnav">
    <div class="subnav-title">门店管理</div>
    <ul>
        {loop $deam_frames $keyItem}
        {if $keyItem['is_hide'] == '1'}
        {if $keyItem['active'] == 'active'}<li class="active"><a href="{$keyItem['url']}">{$keyItem['title']}</a></li>{/if}
        {else}
        <li class="{$keyItem['active']}"><a href="{$keyItem['url']}">{$keyItem['title']}</a></li>
        {/if}
        {/loop}
    </ul>
</div>
<div class="dm-container">
<div class="dm-content">
{if $operation == 'display'}
<div class="table-responsive">
	<table class="table we7-table table-hover">
		<thead>
		<tr>
			<!-- <th style="width:40px;">
				<input type="checkbox" name="checkall" value="" id="checkall" onclick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});"/>
			</th> -->
			<!-- <th style="width:60px;">
				ID
			</th> -->
			<th style="width:200px;">门店名称</th>
			<th style="width:180px;">门店地址</th>
			<th class="text-center" style="width:100px;">营业时间</th>
			<th class="text-center" style="width:80px;">状态</th>
			<th class="text-center" style="width:260px;">操作</th>
		</tr>
		</thead>
		<tbody>
		{if empty($list)}
		<tr><td colspan="5" style="text-align:center">还未添加门店！</td></tr>
		{else}
		{loop $list $item}
		<tr data-toggle="popover" data-trigger="hover" data-placement="left" class="js-goods-img">
			<!-- <td><input type="checkbox" name="items[]" value="{$item['id']}" class="items" /></td> -->
			<!-- <td>{$item['id']}</td> -->
			<td>{$item['name']}{if !empty($item['wxacode'])}<i style="margin-left: 5px;" class="fa fa-qrcode showpop" style="color: #3e3e3e" data-toggle="popover" data-trigger="click" data-placement="right" data-html="true" data-content="<img style='width:200px;height:200px;' src='{php echo $_W['siteroot'].'addons/deam_food/data/wxacode/'.$item['wxacode']}'><p style='text-align:center;color:#999'>发布后小程序码才能生效</p>"></i>{/if}<a href="{php echo $this->createWebUrl('store', array('id' => $item['id'], 'op' => 'copy'))}" style="margin-left: 5px;" class="showtitle" title="一键复制门店" onclick="return confirm('一键复制会将该门店设定数据和商品列表创建成新的门店');return false;"><i class="fa fa-copy"></i></a></td>
			<td>{$item['province']}{$item['city']}{$item['district']}{$item['address']}</td>
			<td class="text-center"><span class="label label-info">{$item['starttime']}-{$item['endtime']}</span></td>
			<td class="text-center">{if empty($item['status'])}<span class="label label-danger">关店</span>{elseif $item['status']=='1'}<span class="label label-success">营业中</span>{elseif $item['status']=='2'}<span class="label label-info">隐藏</span>{/if}</td>
			<td class="text-center">
				<a href="{php echo $this->createWebUrl('store', array('id' => $item['id'], 'op' => 'post'))}" class="btn showtitle btn-default btn-sm" title="编辑商户"><i class="fa fa-edit"></i></a>
                <a href="{php echo $this->createWebUrl('desk', array('store_id' => $item['id']))}" class="btn showtitle btn-default btn-sm" title="桌号管理"><i class="fa fa-cube"></i></a>
				<a href="{php echo $this->createWebUrl('goods', array('store_id' => $item['id']))}" class="btn showtitle btn-default btn-sm" title="商品管理"><i class="fa fa-list"></i></a>
                <a href="{php echo $this->createWebUrl('printer', array('store_id' => $item['id']))}" class="btn showtitle btn-default btn-sm" title="打印机管理"><i class="fa fa-print"></i></a>
                <a href="{php echo $this->createWebUrl('operator', array('store_id' => $item['id']))}" class="btn showtitle btn-default btn-sm" title="店员管理"><i class="fa fa-user"></i></a>
                <a href="{php echo $this->createWebUrl('store', array('id' => $item['id'], 'op' => 'delete'))}" class="btn showtitle btn-default btn-sm" title="删除" onclick="return confirm('此操作不可恢复，确认删除？\r\n商品也会删除！！！');return false;"><i class="fa fa-times"></i></a>
			</td>
		</tr>
		{/loop}
		{/if}
		</tbody>
	</table>
    {$pager}
</div>
<script type="text/javascript">
	require(['bootstrap'], function ($) {
        $('.showtitle').hover(function () {
            $(this).tooltip('show');
        }, function () {
            $(this).tooltip('hide');
        });
        $('.showpop').on('shown.bs.popover', function () {
            $('.showpop').not(this).popover('hide');
        });
        $('[data-toggle="popover"]').popover("destroy").popover({
            container: $(document.body)
        });
    });
</script>
{elseif $operation == 'post'}
<style type="text/css">
	.pl0{padding-left: 0px;}
	.mt10{margin-top: 10px}
	.ml15{margin-left: 15px}
</style>
<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=HYVBZ-RFTAF-ESEJ6-NDOTJ-2QLIQ-PFFFY"></script>
<form action="" method="post" class="form-horizontal form" id="form">
<input type="hidden" name="id" value="{$store['id']}">
    <div class="panel we7-panel panel-default">
        <ul class="we7-page-tab" id="myTab" style="margin-left: 0;margin-right: 0">
            <li class="active"><a href="#tab_basic">基本</a></li>
            <li><a href="#tab_order">订单设定</a></li>
            <li><a href="#tab_takeout">外卖设置</a></li>
            <li><a href="#tab_enough">满减设置</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="tab_basic">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">门店名称</label>
                    <div class="col-md-6">
                        <input type="text" name="store[name]" class="form-control" value="{$store['name']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red"></span>门店地址</label>
                    <script type="text/javascript">
                        require(["jquery", "district"], function($, dis){
                            $(".tpl-district-container").each(function(){
                                var elms = {};
                                elms.province = $(this).find(".tpl-province")[0];
                                elms.city = $(this).find(".tpl-city")[0];
                                elms.district = $(this).find(".tpl-district")[0];
                                var vals = {};
                                vals.province = $(elms.province).attr("data-value");
                                vals.city = $(elms.city).attr("data-value");
                                vals.district = $(elms.district).attr("data-value");
                                dis.render(elms, vals, {withTitle: true});
                            });
                        });
                    </script>
                    <div class="col-sm-9 col-xs-12 tpl-district-container pl0">
                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
                            <select name="store[province]" data-value="{$store['province']}" class="form-control tpl-province">
                            </select>
                        </div>
                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
                            <select name="store[city]" data-value="{$store['city']}" class="form-control tpl-city">
                            </select>
                        </div>
                        <div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
                            <select name="store[district]" data-value="{$store['district']}" class="form-control tpl-district" onchange="codeAddress();">
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-6 col-sm-offset-2 pl0" style="margin-top:15px;padding-left: 15px">
                        <div class="col-sm-8 pl0">
                            <div class="input-group">
                                <input type="text" name="store[address]" class="form-control valid inline address" value="{$store['address']}"placeholder="请输入详细地址，请勿重复填写市区信息">
                                <div class="input-group-btn"><button type="button" title="搜索" onclick="codeAddress();" class="btn btn-default"><i class="fa fa-search"></i></button></div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6 col-sm-offset-2 pl0"><div class="help-block mt10 ml15">注意：这个只是模糊定位，准确位置请地图上标注。 最多50字。</div></div>
                    <div class="col-sm-6 col-sm-offset-2 pl0" style="margin-top:15px;width: 474px;height: 300px; ">
                        <div id="container" style="position: absolute;margin-left:15px;width: 474px; height: 300px;border: 1px solid #e5e6e7;overflow:hidden;">
                        </div>
                    </div>
                    <script>
                    var geocoder,map,marker = null;
                    var markersArray = [];
                    var marker = new qq.maps.Marker();
                    var init = function() {
                        var center = new qq.maps.LatLng(39.916527,116.397128);
                        map = new qq.maps.Map(document.getElementById('container'),{
                            center: center,
                            zoom: 13
                        });
                        //调用地址解析类
                        geocoder = new qq.maps.Geocoder({
                            complete : function(result){
                                map.setCenter(result.detail.location);

                                marker = new qq.maps.Marker({
                                    map:map,
                                    position: result.detail.location,
                                    draggable: true,
                                });
                                console.log(result);
                                $(".longitude").val(result.detail.location.lng);
                                $(".latitude").val(result.detail.location.lat);
                                qq.maps.event.addListener(marker, 'dragend', function(e) {
                                    $(".longitude").val(e.latLng.lng);
                                    $(".latitude").val(e.latLng.lat);
                                });
                            }
                        });
                        {if !empty($store['longitude']) && !empty($store['latitude'])}
                        map.setCenter(new qq.maps.LatLng({$store['latitude']},{$store['longitude']}));
                        marker = new qq.maps.Marker({
                            position: new qq.maps.LatLng({$store['latitude']},{$store['longitude']}),
                            map: map,
                          draggable: true,
                        });
                        qq.maps.event.addListener(marker, 'dragend', function(e) {
                            $(".longitude").val(e.latLng.lng);
                            $(".latitude").val(e.latLng.lat);
                        });
                        // setTimeout(function(){
                        //  codeAddress();
                        // },3000);
                        {/if}
                    }

                    init();
                    function clearOverlays() {
                        if (markersArray) {
                            for (i in markersArray) {
                                markersArray[i].setMap(null);
                            }
                        }
                    }
                    function codeAddress() {
                        var address = $('.tpl-province').val()+$('.tpl-city').val()+$('.tpl-district').val()+ $(".address").val();
                        //通过getLocation();方法获取位置信息值
                        marker.setMap(null);
                        geocoder.getLocation(address);
                    }

                    </script>
                    <div class="col-sm-9 col-sm-offset-2 pl0" style="margin-top:15px;">
                                    
                        <div class="col-xs-4 col-sm-4">
                            <input type="text" name="store[longitude]" value="{$store['longitude']}" readonly="" placeholder="地理经度"  class="form-control longitude" />
                        </div>
                        <div class="col-xs-4 col-sm-4">
                            <input type="text" name="store[latitude]" value="{$store['latitude']}" readonly="" placeholder="地理纬度"  class="form-control latitude" />
                        </div>
                        <div class="help-block"></div>
                    </div>
                    
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店类型</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="checkbox-inline">
                            <input type="checkbox" name="store[is_getself]" value="1" {if $store['is_getself']=='1' || $store['is_getself'] == ''} checked=""{/if}> 自取/店内点餐
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="store[is_takeout]" value="1" {if $store['is_takeout']=='1' || $store['is_takeout'] == ''} checked=""{/if}> 外卖
                        </label>
                        <div class="help-block">至少选择一个</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店状态</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline">
                            <input type="radio" name="store[status]" value="1" {if $store['status']=='' || $store['status'] == '1'} checked=""{/if}> 营业
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="store[status]" value="0" {if $store['status']=='0'} checked=""{/if}> 关店
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="store[status]" value="2" {if $store['status']=='2'} checked=""{/if}> 隐藏
                        </label>
                        <div class="help-block">选择隐藏后，用户列表不可见</div>
                    </div>
                </div>
                <div class="form-group store-closed" {if $store['status']=='' || $store['status'] == '1' || $store['status'] == '2'} style="display: none"{/if}>
                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">关店原因</label>
                    <div class="col-md-6">
                        <input type="text" name="store[close_reason]" class="form-control" value="{$store['close_reason']}" />
                    </div>
                </div>
                <div class="form-group store-opening" {if $store['status']=='0'} style="display: none" {/if}>
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">门店营业时间</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="col-sm-5 col-xs-5 pl0" style="padding-right: 5px">
                            {php echo tpl_form_field_clock('store[starttime]',$store['starttime']);}
                        </div>
                        <span style="float: left;line-height: 34px;color: #98999a;">-</span>
                        <div class="col-sm-5 col-xs-5" style="padding-left: 5px">
                            {php echo tpl_form_field_clock('store[endtime]',$store['endtime']);}
                        </div>
                        <div style="clear: both;"></div>
                        <div class="help-block">如24小时营业请设置为00:00-00:00</div>
                    </div>
                </div>
                <div class="form-group store-closed" {if empty($settings['sms_status'])} style="display: none"{/if}>
                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">订单短信通知</label>
                    <div class="col-md-6">
                        <input type="text" name="store[notice_tel]" class="form-control" value="{$store['notice_tel']}" />
                        <div class="help-block">多个手机号请用英文逗号“,”隔开</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-4 col-md-3 col-lg-2 control-label">顶部标题栏背景色</label>
                    <div class="col-sm-8 col-xs-12">
                        {php echo tpl_form_field_color('store[bg_color]',empty($store['bg_color']) ? '#000000' : $store['bg_color']);}
                        <div class="help-block"><font color="#FF0000">默认为#000000</font></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">顶部标题栏前景色</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline">
                            <input type="radio" name="store[fg_color]" value="#ffffff" {if $store['fg_color']=='' || $store['fg_color'] == '#ffffff'} checked=""{/if}> 白色
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="store[fg_color]" value="#000000" {if $store['fg_color']=='#000000'} checked=""{/if}> 黑色
                        </label>
                        <div class="help-block">包括按钮、标题、状态栏的颜色，仅支持 白色 和 黑色</div>
                    </div>
                </div>
                <!-- <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">门店顶部幻灯片</label>
                    <div class="col-md-6">
                        {php echo tpl_form_field_multi_image('store[imgs]',$store['imgs']);}
                        <div class="help-block">图片建议长宽保持一致。建议尺寸640*350</div>
                    </div>
                </div> -->
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 col-lg-2 control-label">订单备注提示</label>
                    <div class="col-md-6">
                        <input type="text" name="store[remark_text]" class="form-control" value="{$store['remark_text']}" />
                        <div class="help-block">如：如有口味要求，请输入备注</div>
                    </div>
                </div>
            </div>
            <div class="tab-pane" id="tab_order">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">开启自动接单</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline">
                            <input type="radio" name="store[auto_order]" value="1" {if $store['auto_order']=='' || $store['auto_order'] == '1'} checked=""{/if}> 开启
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="store[auto_order]" value="0" {if $store['auto_order']=='0'} checked=""{/if}> 关闭
                        </label>
                        <div class="help-block">开启此功能后用户支付成功自动接单</div>
                    </div>
                </div>
            </div>
            <div class="tab-pane" id="tab_takeout">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">外卖起送价</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class="input-group">
                            <input type="text" class="form-control" name="store[start_price]" value="{$store['start_price']}">
                            <span class="input-group-addon">元</span>
                        </div>
                        <div class="help-block">0为不限制</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">派送范围</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class="input-group">
                            <input type="text" class="form-control" name="store[send_limit]" value="{$store['send_limit']}">
                            <span class="input-group-addon">公里内，配送费</span>
                            <input type="text" class="form-control" name="store[send_fee]" value="{$store['send_fee']}">
                            <span class="input-group-addon">元</span>
                        </div>
                        <div class="help-block">以店铺地址为中心点的半径范围</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择配送方式</label>
                    <div class="col-sm-9 col-xs-12">
                        <label class="radio-inline">
                            <input type="radio" name="store[deliver_type]" value="0" {if empty($store['deliver_type']) || empty($settings['deliver_dada_status'])} checked=""{/if}> 商家配送
                        </label>
                        <label class="radio-inline">
                            <input {if empty($settings['deliver_dada_status'])} disabled="" {/if} type="radio" name="store[deliver_type]" value="1" {if $store['deliver_type']=='1' && $settings['deliver_dada_status'] == '1'} checked=""{/if}> 达达配送
                        </label>
                        <div class="help-block"></div>
                    </div>
                </div>
                <div class="deliver-dada" {if empty($store['deliver_type']) || empty($settings['deliver_dada_status'])} style="display: none"{/if}>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店编号</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="store[deliver_dada_shopno]" class="form-control" value="{$store['deliver_dada_shopno']}" />
                        <div class="help-block">请至http://newopen.imdada.cn注册账号并创建门店</div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">门店所在城市区号</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="store[deliver_dada_citycode]" class="form-control" value="{$store['deliver_dada_citycode']}" />
                        <div class="help-block">如南京：025</div>
                    </div>
                </div>
                </div>
            </div>
            <div class="tab-pane" id="tab_enough">
                <div class="form-group">
                    <div class="col-sm-9 col-xs-12">
                        <div class="input-group">
                            <span class="input-group-addon">单笔订单满</span>
                            <input type="text" class="form-control" name="store[enoughmoney]" value="{$store['enoughmoney']}">
                            <span class="input-group-addon">元，减</span>
                            <input type="text" class="form-control" name="store[enoughdeduct]" value="{$store['enoughdeduct']}">
                            <span class="input-group-addon">元</span>
                        </div>
                        <div class="help-block">两个值都设置才生效，最低消费必须大于减免金额</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
	
	<div class="form-group col-sm-12">
		<input type="hidden" name="id" value="{$store['id']}" />
		<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
		<input type="hidden" name="token" value="{$_W['token']}" />
	</div>
</form>
<script type="text/javascript">
$(function () {
    window.optionchanged = false;
    $('#myTab a').click(function (e) {
        e.preventDefault();//阻止a链接的跳转行为
        $(this).tab('show');//显示当前选中的链接及关联的content
    })

});
$('input[name="store[status]"]').click(function(){
    var storeStatus = $(this).val();
    if(storeStatus == 1){
        $('.store-opening').show();
        $('.store-closed').hide();
    }else if(storeStatus == 0){
        $('.store-closed').show();
        $('.store-opening').hide();
    }else if(storeStatus == 2){
        $('.store-closed').hide();
        $('.store-opening').show();
    }
});
$('input[name="store[deliver_type]"]').click(function(){
    var deliver = $(this).val();
    if(deliver == 1){
        $('.deliver-dada').show();
    }else{
        $('.deliver-dada').hide();
    }
})
$('#form').submit(function(){
    if((!$('input[name="store[is_getself]"]').is(':checked')) && (!$('input[name="store[is_takeout]"]').is(':checked'))){
        util.message("门店类型必须选择一个！");
        return false;
    }
    return true;
});

</script>
{/if}
</div>
{template 'system/common/footer'}